qui(function(require, exports, module) {
	News.Util = $.extend(true, {}, EpgWeb.Util, {
			formatter: {
			    channel_status: function (cellvalue, options, rowObject) {
                    if (cellvalue == 1) {
                        return "收录中"
                    } else if (cellvalue == null) {
                        return "错误";
                    }
                    return "未收录";
                },
                freeType: function (cellvalue, options, rowObject) {
                    if (cellvalue == 1) {
                        return "是"
                    }
                    return "否"
                },
                channel_ip: function (cellvalue, options, rowObject) {
                    if (cellvalue == null || News.Config.IP_LINK_AREA[cellvalue] == null) {
                        return "未知"
                    }
                    return News.Config.IP_LINK_AREA[cellvalue]
                },
                repeatInfo:function(v,r) {
                    var str = "";
                    for(var i in r.repeat_info)
                    {
                        str += News.Config.REPEAT_INFO[r.repeat_info[i]-1]+',';
                    }

                    return str.substr(0,str.length-1);
                },
                channelArea:function(v,r) {
                    return News.Config.REGION_CH_LIST[v];
                },
                startTime:function(v,r) {
                    return v;
                },
                stopTime:function(v,r) {
                    return v;
                },
                status:function(v,r) {
                    var str = "当前有" + r.count + "条待审核";
                    var startTime = r.start_time.split(":");
                    var startHours = startTime[0];
                    var startMinutes = startTime[1];
                    var startMinutesTime = parseInt(startHours) * 60 + parseInt(startMinutes);
                    var stopTime = r.stop_time.split(":");
                    var stopHours = stopTime[0];
                    var stopMinutes = stopTime[1];
                    var stopMinutesTime = parseInt(stopHours) * 60 + parseInt(stopMinutes);

                    var today = new Date();
                    var curMinutesTime = today.getHours() * 60 + today.getMinutes();

                    var targetday_milliseconds=today.getTime() - 1000*60*60*24*1;
                    var yesterday = new Date();
                    yesterday.setTime(targetday_milliseconds);

                    targetday_milliseconds = today.getTime() + 1000*60*60*24*1;
                    var tomorrow = new Date();
                    tomorrow.setTime(targetday_milliseconds);

                    var startFormatDate = "";
                    var stopFormatDate = "";
                    if (startMinutesTime < stopMinutesTime) {
                        if (curMinutesTime < startMinutesTime) {
                            yesterday.setHours(parseInt(startHours));
                            yesterday.setMinutes(parseInt(startMinutes));
                            yesterday.setSeconds(0);
                            startFormatDate = yesterday.format("yyyy-MM-dd hh:mm:ss");
                            yesterday.setHours(parseInt(stopHours));
                            yesterday.setMinutes(parseInt(stopMinutes));
                            stopFormatDate = yesterday.format("yyyy-MM-dd hh:mm:ss");
                        } else {
                            today.setHours(parseInt(startHours));
                            today.setMinutes(parseInt(startMinutes));
                            today.setSeconds(0);
                            startFormatDate = today.format("yyyy-MM-dd hh:mm:ss");
                            today.setHours(parseInt(stopHours));
                            today.setMinutes(parseInt(stopMinutes));
                            stopFormatDate = today.format("yyyy-MM-dd hh:mm:ss");
                        }
                    } else {
                        if (curMinutesTime < startMinutesTime) {
                            yesterday.setHours(parseInt(startHours));
                            yesterday.setMinutes(parseInt(startMinutes));
                            yesterday.setSeconds(0);
                            startFormatDate = yesterday.format("yyyy-MM-dd hh:mm:ss");
                            today.setHours(parseInt(stopHours));
                            today.setMinutes(parseInt(stopMinutes));
                            today.setSeconds(0);
                            stopFormatDate = today.format("yyyy-MM-dd hh:mm:ss");
                        } else {
                            today.setHours(parseInt(startHours));
                            today.setMinutes(parseInt(startMinutes));
                            today.setSeconds(0);
                            startFormatDate = today.format("yyyy-MM-dd hh:mm:ss");
                            tomorrow.setHours(parseInt(stopHours));
                            tomorrow.setMinutes(parseInt(stopMinutes));
                            tomorrow.setSeconds(0);
                            stopFormatDate = tomorrow.format("yyyy-MM-dd hh:mm:ss");
                        }
                    }

                    var href = "/epg/dadian_news.html?" + r.channel_code + "=" + r.channel_ip + "&free_type=0&channel_id=" + r.channel_id + "&cn=" + r.channel_name + "&location=&locationCategory=-1&startTime=" + startFormatDate + "&endTime=" + stopFormatDate;
                    if (r.count == 0) {
                        return News.Config.NEWS_STATUS[v] + " | " + str;
                    } else {
                        return News.Config.NEWS_STATUS[v] + " | " + "<a href='" + href + "' target='_blank'>" + str + "</a>";
                    }
                },
                operate:function(v,r) {
                    var str = "<a href='/epg/news_edit.html?programId=" + r.program_id + "' target='_blank'>修改</a>";
                    str += " | " + "<a href='javascript:void(0);' onclick='News.Util.del(" + r.program_id + ")' target='_blank'>删除</a>";
                    //str += " | " + "<a href=''target='_blank'>当日时间重置</a>";
                    return str;
                },
                statisticsShow:function(v,r) {
                    return "<a href='' target='_blank'>拆条相关数据</a>";
                }

			},
			del: function(program_id){
                var self = this;
                if(window.confirm('是否从自动拆条列表中删除该节目？')) {
                    var params = {func: 'delete_ablum', program_id: program_id};
                    News.Dao.modify(params, function(){
                        $('.query-btn').click();
                    });
                    return true;
                }
            }

		});
});